package richbar.com.richbar.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by qyang on 2018-4-22.
 */

public abstract class BaseListAdapter<T> extends BaseAdapter {
    public Context context;
    public LayoutInflater inflater;
    public List<T> data;

    public BaseListAdapter(Context context, List<T> data) {
        this.context = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return null == data ? 0 : data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        return convert(i,view,viewGroup,data.get(i));
    }

    public abstract View convert(int i, View view, ViewGroup viewGroup,T bean);

    public void setNewData(List<T> data) {
        this.data = data;
        notifyDataSetChanged();
    }
}
